﻿using HardcoreGame.Content.Buffs;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.WorldBuilding;

namespace HardcoreGame.Common.GlobalNPCs
{
    public class SentryNPC : GlobalNPC
    {
        private static Terraria.WorldBuilding.Conditions.IsSolid _cachedConditions_solid = new();

        private static Terraria.WorldBuilding.Conditions.NotNull _cachedConditions_notNull = new();
        public override bool InstancePerEntity => true;
        protected override bool CloneNewInstances => true;
        public override void ModifyHitByProjectile(NPC npc, Projectile projectile, ref NPC.HitModifiers modifiers)
        {
            if (npc.HasBuff<BeckysCurse>())
            {
                if (ProjectileID.Sets.SentryShot[projectile.type])
                {
                    if (!WorldUtils.Find(npc.Center.ToTileCoordinates(), Searches.Chain(new Searches.Down(12), _cachedConditions_notNull, _cachedConditions_solid), out var _))
                    {
                        modifiers.FinalDamage *= 3;
                    }
                    modifiers.FinalDamage *= 2;
                }
            }
        }
    }
}
